﻿package client;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;

import server.PersonInterface;
import server.ResStaffInterface;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import client.Configuration;

public class ResApplyGUI extends JDialog {
	private JTextField textField;
	private JTextField textField_1;

	
	private int select;
	private int select_1;
	private double salary;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			ResApplyGUI dialog = new ResApplyGUI();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public ResApplyGUI() {
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setTitle("\u6B22\u8FCE\u5E94\u8058");
		setBounds(100, 100, 450, 339);
		getContentPane().setLayout(null);
		
		JLabel label = new JLabel("\u59D3\u540D");
		label.setBounds(53, 39, 47, 25);
		label.setFont(new Font("方正舒体", Font.PLAIN, 18));
		getContentPane().add(label);
		
		JLabel lblNewLabel = new JLabel("\u6027\u522B");
		lblNewLabel.setFont(new Font("方正舒体", Font.PLAIN, 18));
		lblNewLabel.setBounds(53, 93, 83, 31);
		getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("\u5E74\u9F84");
		lblNewLabel_1.setFont(new Font("方正舒体", Font.PLAIN, 18));
		lblNewLabel_1.setBounds(53, 154, 83, 31);
		getContentPane().add(lblNewLabel_1);
		
		textField = new JTextField();
		textField.setBounds(128, 43, 104, 21);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel label_1 = new JLabel("\u7533\u8BF7\u804C\u4F4D");
		label_1.setFont(new Font("方正舒体", Font.PLAIN, 18));
		label_1.setBounds(37, 214, 72, 22);
		getContentPane().add(label_1);
		
		textField_1 = new JTextField();
		textField_1.setBounds(128, 161, 104, 21);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		String a[]={"服务员","厨师"};
		String b[]={"男","女"};
		JComboBox comboBox = new JComboBox(a);
		comboBox.setBounds(132, 211, 100, 25);
		getContentPane().add(comboBox);
		
		
		JComboBox comboBox_1 = new JComboBox(b);
		comboBox_1.setBounds(128, 100, 100, 24);
		getContentPane().add(comboBox_1);
		
	    select=comboBox.getSelectedIndex()+1;
	    select_1=comboBox_1.getSelectedIndex()+1;
	    
	    if(select==1)
	    	salary=2000;
	    else
	    	salary=3000;
	    	
		
		JButton button = new JButton("\u786E\u8BA4\u7533\u8BF7");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Configuration config=new Configuration();
				String rmiAddress=config.getRmiAddress();
				try {
					dispose();
					ResStaffInterface staff=(ResStaffInterface)Naming.lookup(rmiAddress+"ResStaffList");
				    PersonInterface p=(PersonInterface)Naming.lookup(rmiAddress+"Person");
				    Person p1=new Person();
				   int exp=p.getExp(p1.getPID());
				   
				   if(exp<40)
				   {
					   JOptionPane.showMessageDialog(null, "对不起！您经验值不足");
				   }
				   else{
					   					
					int number=staff.addStaff(select,textField.getText(),select_1, new Integer(textField_1.getText()), salary);
					
					JOptionPane.showMessageDialog(null,"恭喜您已成为本店"+number+"号员工！");
					}
				} catch (NumberFormatException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (MalformedURLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button.setFont(new Font("方正舒体", Font.PLAIN, 18));
		button.setBounds(306, 256, 104, 23);
		getContentPane().add(button);
		

	}
}
